package com.ccsoft.leetcode.service;

import org.springframework.stereotype.Service;

/**
 * 66. 加一
 */
@Service
public class Increase1 {
    public int[] plusOne(int[] digits) {
        int j = 1;
        for(int i=digits.length-1;i>=0;i--){
            if(digits[i] == 9 ){
                digits[i] = 0;
                j = i;
            }else{
                digits[i] += 1;
                break;
            }
        }
        if( j == 0 ){
            int[] ret = new int[digits.length+1];
            ret[0] = 1;
            for(int i=1;i<ret.length;i++){
                ret[i] = 0;
            }
            return ret;
        }

        return digits;
    }
}
